
define([
    './custom/widgets/js/yufpOrgTree.js',
    './custom/plugins/YufpMgrSelector.js',
    './custom/widgets/js/yufpExtTree.js'

], function (require, exports) {
    exports.ready = function (hashCode, data, cite) {
        // 注册该功能要用到的数据字典
        yufp.lookup.reg('YES_NO,INDUSTRY_TYPE,DATA_STS,FAMILIARITY_LEVEL,MAIN_OR_OTHER');
        // 创建virtual model
        yufp.custom.vue({
            el: '#villageInformation',
            // 以m_开头的属性为UI数据不作为业务数据，否则为业务数据
            data: function () {
                var me = this;
                    return {
                        options2:[],
                        options: [{
                            value: "1",
                            label: "1月"
                        }, {
                            value: "2",
                            label: "2月"
                        }, {
                            value: "3",
                            label: "3月"
                        }, {
                            value: "4",
                            label: "4月"
                        }, {
                            value: "5",
                            label: "5月"
                        },{
                            value: "6",
                            label: "6月"
                        },{
                            value: "7",
                            label: "7月"
                        },{
                            value: "8",
                            label: "8月"
                        },{
                            value: "9",
                            label: "9月"
                        },{
                            value: "10",
                            label: "10月"
                        },{
                            value: "11",
                            label: "11月"
                        },{
                            value: "12",
                            label: "12月"
                        }],
                        otherOptions: [{
                            value: "1",
                            label: "1月"
                        }, {
                            value: "2",
                            label: "2月"
                        }, {
                            value: "3",
                            label: "3月"
                        }, {
                            value: "4",
                            label: "4月"
                        }, {
                            value: "5",
                            label: "5月"
                        },{
                            value: "6",
                            label: "6月"
                        },{
                            value: "7",
                            label: "7月"
                        },{
                            value: "8",
                            label: "8月"
                        },{
                            value: "9",
                            label: "9月"
                        },{
                            value: "10",
                            label: "10月"
                        },{
                            value: "11",
                            label: "11月"
                        },{
                            value: "12",
                            label: "12月"
                        }],
                        // options: [{
                        //     value: "1",
                        //     label: new Date().getFullYear()+"-01"
                        // }, {
                        //     value: "2",
                        //     label: new Date().getFullYear()+"-02"
                        // }, {
                        //     value: "3",
                        //     label: new Date().getFullYear()+"-03"
                        // }, {
                        //     value: "4",
                        //     label: new Date().getFullYear()+"-04"
                        // }, {
                        //     value: "5",
                        //     label: "-05"
                        // },{
                        //     value: "6",
                        //     label: new Date().getFullYear()+"-06"
                        // },{
                        //     value: "7",
                        //     label: new Date().getFullYear()+"-07"
                        // },{
                        //     value: "8",
                        //     label: new Date().getFullYear()+"-08"
                        // },{
                        //     value: "9",
                        //     label: new Date().getFullYear()+"-09"
                        // },{
                        //     value: "10",
                        //     label: new Date().getFullYear()+"-10"
                        // },{
                        //     value: "11",
                        //     label: new Date().getFullYear()+"-11"
                        // },{
                        //     value: "12",
                        //     label: new Date().getFullYear()+"-12"
                        // }],
                        fundDemand: [],
                        fpcwgy: !yufp.session.checkCtrl('fpcwgy'),
                        otherFundDemand: [],
                        otherIndustry: [],
                        headers:{
                            'Authorization': 'Bearer ' + yufp.service.getToken(),
                        },
                        addVillageInfo:{
                            isDocument:'',
                            sceneType:'',
                        },
                        villageInfo:{},
                        assignGridPersonnelInfo:{},
                        addVillageRules:{
                            villageName:[
                                {required: true, message: '必填项', trigger: 'blur'}
                            ],
                            orgId:[
                                {required: true, message: '必填项', trigger: 'blur'}
                            ]
                        },processApprovalRules:{
                            villageName:[
                                {required: true, message: '必填项', trigger: 'blur'}
                            ],
                            orgId:[
                                {required: true, message: '必填项', trigger: 'blur'}
                            ]
                        },
                        assignGridPersonnelVisible:false,
                        addVillageInformationRules: {
                            womanPhoneNo: [
                                {required: false, validator: yufp.validator.mobile, message: "请输入正确的11位手机号", trigger: 'blur' }
                            ],
                            phoneNo: [
                                {required: false, validator: yufp.validator.mobile, message: "请输入正确的11位手机号", trigger: 'blur' }
                            ],
                        },
                        updateVillageInformationRules: {
                            mainOrOther:[
                                {required: true, message: '必填项', trigger: 'blur'}
                            ],
                            custName:[
                                {required: true, message: '必填项', trigger: 'blur'}
                            ],
                            isWeixin:[
                                {required: true, message: '必填项', trigger: 'blur'}
                            ],
                            custPhone:[
                                {required: true, message: '必填项', trigger: 'blur'}
                            ],


                        },
                        addOtherIndustryRules: {
                            industryType: [
                                {required: true, message: '必填项', trigger: 'blur'}
                            ],
                            industryName: [
                                {required: true, message: '必填项', trigger: 'blur'}
                            ],
                            industryCharacteristics: [
                                {required: true, message: '必填项', trigger: 'blur'}
                            ]
                        },
                        villageDetail:{},
                        villagePersonInfo:{},
                        otherIndustryDetail:{},
                        addOtherIndustryInfo:{},
                        villageData:{condition: JSON.stringify({
                                userId: yufp.session.userId,
                                orgId: yufp.session.user.org.code,
                                roleId:yufp.session.user.roles[0].code,
                                isDocument:1
                            })},
                        funcDataUrl:backend.msmFrontWebService + '/api/villageInformation/getAllVillageInformation',
                        uploadData:{condition: JSON.stringify({
                                userId: yufp.session.userId,
                                orgId: yufp.session.user.org.code,
                            })},
                        villageCustListDialogVisible:false,
                        otherIndustryCustListDialogVisible:false,
                        otherIndustryDataUrl:backend.msmFrontWebService + '/api/villageInformation/getOtherIndustry',
                        villageCustListDataUrl:backend.msmFrontWebService + '/api/villageInformation/getVillageCustList',
                        otherIndustryCustListDataUrl:backend.msmFrontWebService + '/api/villageInformation/getOtherIndustryCustList',
                        otherIndustryData:{condition: JSON.stringify({
                                userId: yufp.session.userId,
                                orgId: yufp.session.user.org.code,
                                roleId:yufp.session.user.roles[0].code,
                            })},
                        villageCustListData:{condition: JSON.stringify({
                                userId: yufp.session.userId,
                                orgId: yufp.session.user.org.code,
                                roleId:yufp.session.user.roles[0].code,
                            })},
                        otherIndustryCustListData:{condition: JSON.stringify({
                                userId: yufp.session.userId,
                                orgId: yufp.session.user.org.code,
                                roleId:yufp.session.user.roles[0].code,
                            })},
                        dialogImageUrl: '',
                        villageDetailImage:{},
                        otherIndustryDetailImage:{},
                        fileName:'',
                        imageList:[],
                        dialogImgVisible: false,
                        addOtherIndustryVisible:false,
                        otherIndustryDialogVisible:false,
                        addVillageVisible:false,
                        updateVillageDetailVisible:false,
                        updateOtherIndustryFormVisible:false,
                        updateOtherIndustryDetailVisible:false,
                        getVillageDetailVisible:false,
                        getOtherIndustryDetailVisible:false,
                        importDialogVisible: false,
                        addVillageInformationFormVisible: false,
                        getVillagePersonInformationFormVisible: false,
                        dialogStatus: '',
                        saveBtnShow:'',
                        formDisabled: false,
                        loading: false,
                        uploadAction: '/api/CustCenter/uploadExcel',
                        imageAction: '/api/villageInformation/fileUpload',
                        fileList: [],
                        url: '',
                        srcList: [],
                };
            },
            computed: {
                action: function () {
                    var _this = this;
                    return yufp.service.getUrl({ url: _this.imageAction });
                },
                uploadAction: function () {
                    // 获取全路径
                    var me = this;
                    return yufp.service.getUrl({url: me.imageAction});
                }

            },
            // 钩子
            created:function (){
                // this.judgeUserFn()
            },
            mounted: function () {
                // this.getGridName()
            },
            methods: {
                changeIndustryType:function (){
                    var me =this;
                    if (this.$refs.villageDetailForm.formdata.mainOrOther === '2'){
                        this.getOtherIndustryName()
                    }else {
                        me.options2 =[];
                    }
                },
                getOtherIndustryName:function (){
                    var me =this;
                    yufp.service.request({
                        url: backend.msmFrontWebService + '/api/villageInformation/getOtherIndustryName',
                        method: 'get',
                        data: {
                            condition: JSON.stringify({
                                 id:this.$refs.villageTable.selections[0].id,
                            })
                        },
                        callback: function (code, message, response) {
                            me.options2 = response.data
                        }
                    });
                },
                // 文件上传前触发
                handleBeforeUpload:function (file){

                },
                onImgSuccess: function (response, file, fileList) {
                    var me =this;
                    // let pictureList = ['url1', 'url2'];
                    console.log(me.fileList);
                    me.imageList = [];
                    for (let i =0;i<fileList.length;i++){
                        me.imageList.push(fileList[i].name)
                    }
                },
                handleRemove(file, fileList) {
                    console.log(file, fileList);
                },
                handlePreview(file) {
                    console.log(file);
                },
                handleExceed(files, fileList) {
                    this.$message.warning(`当前限制选择 3 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`);
                },
                beforeRemove(file, fileList) {
                    // return this.$confirm(`确定移除 ${ file.name }？`);
                },
                beforeUpload:function (file){
                    // 拿到文件后缀名
                    const fileType = file.name.substring(file.name.lastIndexOf('.') + 1)
                    console.log('文件上传类型', fileType)
                    // 当然拉我的需求是只需要图片和pdf，大家有需要可以在此处扩展
                    const isJpg = fileType === 'jpg'
                    const isPng = fileType === 'png'
                    const isJpeg = fileType === 'jpeg'
                    // const isLt1M = file.size / 1024 / 1024 < 1;
                    // 根据后缀名判断文件类型
                    if (!isJpg && !isPng && !isJpeg) {
                        this.$message({message: '只能上传图片和pdf格式的文件', type: 'warning'});
                        return false
                    }
                    // 可以限制图片的大小
                    // if (!isLt1M) {
                    //     this.$message.error('上传图片大小不能超过 1MB!');
                    // }
                    return isJpg || isPng || isJpeg
                },
                //搜索关联
                searchFn: function () {
                    var me = this;
                    var param = {
                        condition: JSON.stringify({
                            searchOrgId: me.$refs.villageInfoSearch.formdata.orgId,
                            // custName: me.$refs.villageInfoSearch.formdata.custName,
                            // custLevel: me.$refs.villageInfoSearch.formdata.custLevel,
                            // custGridId: me.$refs.villageInfoSearch.formdata.custGridId,
                            // gridId: me.$refs.villageInfoSearch.formdata.custOrgId,
                            // ctfNo: me.$refs.villageInfoSearch.formdata.ctfNo,
                            // custOrgId: me.$refs.villageInfoSearch.formdata.custOrgId
                        })
                    };
                    me.$refs.villageTable.remoteData(param);
                },
                //新增行政村信息
                addVillageFunc:function (){
                    let _this=this;
                    let validate = false;
                    _this.$refs.addVillageForm.validate(function (valid) {
                        validate = valid;
                    });
                    if (!validate) {
                        this.$message({message: '打*为必填项', type: 'warning'});
                        return;
                    }
                    this.loading = true;
                    yufp.service.request({
                        url: backend.msmFrontWebService + '/api/villageInformation/addVillage',
                        method: 'get',
                        data: {
                            condition: JSON.stringify({
                                orgId:_this.addVillageInfo.orgId,
                                userId: yufp.session.userId,
                                villageName:_this.addVillageInfo.villageName
                            })
                        },
                        callback: function (code, message, response) {
                            _this.addVillageVisible=false;
                            _this.loading = false;
                            _this.$refs.villageTable.remoteData();
                        }
                    });
                },
                //新增其他行业功能
                addOtherIndustryFunc:function (){
                    let _this=this;
                    let validate = false;
                    _this.$refs.addOtherIndustryForm.validate(function (valid) {
                        validate = valid;
                    });
                    if (!validate) {
                        this.$message({message: '打*为必填项', type: 'warning'});
                        return;
                    }
                    let s = []
                    for(let i = 0; i < this.otherFundDemand.length; i++) {
                        s.push(this.otherFundDemand[i])
                    }
                    this.otherFundDemand = s.join();
                    this.loading = true;
                    yufp.service.request({
                        url: backend.msmFrontWebService + '/api/villageInformation/addOtherIndustry',
                        method: 'get',
                        data: {
                            condition: JSON.stringify({
                                id:this.$refs.villageTable.selections[0].id,
                                industryType:_this.addOtherIndustryInfo.industryType,
                                industryName:_this.addOtherIndustryInfo.industryName,
                                industryCharacteristics:_this.addOtherIndustryInfo.industryCharacteristics,
                                fundDemand:_this.otherFundDemand
                            })
                        },
                        callback: function (code, message, response) {
                            _this.$refs.otherIndustryTable.remoteData();
                            _this.$refs.villageTable.remoteData();
                            _this.loading = false;
                            _this.addOtherIndustryVisible=false;
                        }
                    });
                },
                //点击按钮查询到村信息显示在页面上
                getVillageInformation:function (){
                    var _this =this;
                    if (this.$refs.villageTable.selections.length !== 1) {
                        this.$message({message: '请选择一个选项', type: 'warning'});
                        return;
                    }
                    _this.addVillageInformationFormVisible  = true;
                    yufp.service.request({
                        url: backend.msmFrontWebService + '/api/villageInformation/getVillageInformation',
                        method: 'get',
                        data: {
                            condition: JSON.stringify({
                                id:this.$refs.villageTable.selections[0].id
                            })
                        },
                        callback: function (code, message, response) {
                            if (code === 0) {
                                var arrIntSet = []
                                if(null!=response.data.fundDemand&&""!=response.data.fundDemand){
                                    // 将字符串转换成数组，此时是字符串数组
                                    var arrString = response.data.fundDemand.split(',')
                                    // 将字符串数组的每一项转换成Number，生成一个新的数组
                                    for (var arrInt in arrString) {
                                        arrIntSet.push(arrString[arrInt])
                                    }
                                }
                                // 将新的Number数组，绑定到select空间的v-model上
                                _this.fundDemand  = arrIntSet;
                                _this.villageInfo.mrgId = response.data.mrgId;
                                _this.villageInfo.villageName = response.data.villageName;
                                _this.villageInfo.orgId = response.data.orgId;
                                _this.villageInfo.villageSecretaryName = response.data.villageSecretaryName;
                                _this.villageInfo.phoneNo = response.data.phoneNo;
                                _this.villageInfo.familiarityLevel = response.data.familiarityLevel;
                                _this.villageInfo.womanDirectorName = response.data.womanDirectorName;
                                _this.villageInfo.womanPhoneNo = response.data.womanPhoneNo;
                                _this.villageInfo.womanFamiliarityLevel = response.data.womanFamiliarityLevel;
                                _this.villageInfo.accountingName = response.data.accountingName;
                                _this.villageInfo.accountingPhoneNo = response.data.accountingPhoneNo;
                                _this.villageInfo.accountingFamiliarityLevel = response.data.accountingFamiliarityLevel;
                                _this.villageInfo.captainName = response.data.captainName;
                                _this.villageInfo.captainPhoneNo = response.data.captainPhoneNo;
                                _this.villageInfo.captainFamiliarityLevel = response.data.captainFamiliarityLevel;
                                _this.villageInfo.industryType = response.data.industryType;
                                _this.villageInfo.industryName = response.data.industryName;
                                _this.villageInfo.industryCharacteristics = response.data.industryCharacteristics;
                            } else {
                            }
                        }
                    });
                },
                //点击按钮查询到村信息显示在页面上
                getVillagePersonInformation:function (row){
                    var _this =this;
                    _this.getVillagePersonInformationFormVisible  = true;
                    yufp.service.request({
                        url: backend.msmFrontWebService + '/api/villageInformation/getVillageInformation',
                        method: 'get',
                        data: {
                            condition: JSON.stringify({
                                id:row.id
                            })
                        },
                        callback: function (code, message, response) {
                            if (code === 0) {
                                // 将新的Number数组，绑定到select空间的v-model上
                                _this.villagePersonInfo.villageSecretaryName = response.data.villageSecretaryName;
                                _this.villagePersonInfo.phoneNo = response.data.phoneNo;
                                _this.villagePersonInfo.familiarityLevel = response.data.familiarityLevel;
                                _this.villagePersonInfo.womanDirectorName = response.data.womanDirectorName;
                                _this.villagePersonInfo.womanPhoneNo = response.data.womanPhoneNo;
                                _this.villagePersonInfo.womanFamiliarityLevel = response.data.womanFamiliarityLevel;
                                _this.villagePersonInfo.accountingName = response.data.accountingName;
                                _this.villagePersonInfo.accountingPhoneNo = response.data.accountingPhoneNo;
                                _this.villagePersonInfo.accountingFamiliarityLevel = response.data.accountingFamiliarityLevel;
                                _this.villagePersonInfo.captainName = response.data.captainName;
                                _this.villagePersonInfo.captainPhoneNo = response.data.captainPhoneNo;
                                _this.villagePersonInfo.captainFamiliarityLevel = response.data.captainFamiliarityLevel;
                            } else {
                            }
                        }
                    });
                },
                //新增其他行业按钮点击显示弹窗
                addOtherIndustry:function (){
                    var _this = this;
                    _this.$nextTick(function () {
                        if (_this.$refs.addOtherIndustryForm){
                            _this.$refs.addOtherIndustryForm.resetFields();
                        }
                    });
                    _this.otherFundDemand=[];
                    _this.addOtherIndustryVisible = true;
                },
                deleteOtherIndustry:function (){
                    var _this = this;
                    if (_this.$refs.otherIndustryTable.selections.length === 0) {
                        _this.$message({message: '请选择至少一个选项', type: 'warning'});
                        return;
                    }
                    var industryIdArray =[];
                    for (var i=0;i<_this.$refs.otherIndustryTable.selections.length;i++){
                        industryIdArray.push(_this.$refs.otherIndustryTable.selections[i].industryId)
                    }
                    yufp.service.request({
                        url: backend.msmFrontWebService + '/api/villageInformation/deleteOtherIndustry',
                        method: 'get',
                        data: {
                            condition: JSON.stringify({
                                industryId:industryIdArray
                            })
                        },
                        callback: function (code, message, response) {
                            _this.$refs.otherIndustryTable.remoteData();
                            if (response !== 0) {
                                _this.$message({message: '删除成功', type: 'success'});
                                //获取上级网格名称和ID
                            } else {
                                console.info("失败");
                            }
                        }
                    });
                },
                assignGridPersonnelFunc:function (){
                    var _this = this;
                    yufp.service.request({
                        url: backend.msmFrontWebService + '/api/villageInformation/updateGridPersonnel' ,
                        method: 'get',
                        data: {
                            condition: JSON.stringify({
                                id:this.$refs.villageTable.selections[0].id,
                                mrgId1:_this.assignGridPersonnelInfo.mrgId1,
                                mrgId2:_this.assignGridPersonnelInfo.mrgId2,
                            })
                        },
                        callback: function (code, message, response) {
                            _this.assignGridPersonnelVisible  = false;
                            _this.$refs.villageTable.remoteData();
                            _this.$nextTick(function () {
                                if (_this.$refs.villageDetailForm){
                                    _this.$refs.villageDetailForm.resetFields();
                                }
                            });
                            _this.$message({message: '分配网格员成功', type: 'success'});
                        }
                    });
                },
                //行政村信息收集
                updateVillageDetail:function (){
                    var _this = this;
                    //选项校验
                    if (this.$refs.villageTable.selections.length !== 1) {
                        this.$message({message: '请选择一个选项', type: 'warning'});
                        return;
                    }
                    _this.updateVillageDetailVisible = true;
                    _this.$nextTick(function () {
                        if (_this.$refs.villageDetailForm){
                            _this.$refs.villageDetailForm.resetFields();
                        }
                    });
                    _this.fileList = [];
                    // yufp.service.request({
                    //     url: backend.msmFrontWebService + '/api/villageInformation/getVillageDetail',
                    //     method: 'get',
                    //     data: {
                    //         condition: JSON.stringify({
                    //             id:this.$refs.villageTable.selections[0].id
                    //         })
                    //     },
                    //     callback: function (code, message, response) {
                    //         if (code === 0) {
                    //             _this.villageDetail.custName = response.data.custName;
                    //             _this.villageDetail.custPhone = response.data.custPhone;
                    //             _this.villageDetail.isWeixin = response.data.isWeixin;
                    //             _this.fileList=response.data.fileList;
                    //         } else {
                    //         }
                    //     }
                    // });
                },
                //单独查看村详细并且展示图片
                getVillageCustDetailFn:function (row){
                    var _this = this;
                    //选项校验
                    // if (_this.$refs.villageCustListTable.selections.length === 0) {
                    //     _this.$message({message: '请选择至少一个选项', type: 'warning'});
                    //     return;
                    // }
                    _this.url = '';
                    _this.getVillageDetailVisible = true;
                    yufp.service.request({
                        url: backend.msmFrontWebService + '/api/villageInformation/getVillageCustDetailImage',
                        method: 'get',
                        data: {
                            condition: JSON.stringify({
                                //此处id为查询时的custId
                                id:row.id
                            })
                        },
                        callback: function (code, message, response) {
                            if (code === 0) {
                                // _this.villageDetailImage.custName = response.data.custName;
                                // _this.villageDetailImage.custPhone = response.data.custPhone;
                                // _this.villageDetailImage.isWeixin = response.data.isWeixin;
                                let val = response.data.fileList
                                _this.url=val[0].url;
                                var urlList = [] ;
                                for(var i = 0; i < val.length; i++) {
                                    urlList[i] = val[i].url;
                                }
                                _this.srcList= urlList;
                            } else {
                            }
                        }
                    });
                },
                //单查看次要行业详细并且展示图片
                getOtherIndustryDetailFn:function (row){
                    var _this = this;
                    //选项校验
                    // if (this.$refs.otherIndustryTable.selections.length !== 1) {
                    //     this.$message({message: '请选择一个选项', type: 'warning'});
                    //     return;
                    // }
                    _this.url = '';
                    _this.getOtherIndustryDetailVisible = true;
                    yufp.service.request({
                        url: backend.msmFrontWebService + '/api/villageInformation/getOtherIndustryCustDetailImage',
                        method: 'get',
                        data: {
                            condition: JSON.stringify({
                                id:row.id
                            })
                        },
                        callback: function (code, message, response) {
                            if (code === 0) {
                                // _this.otherIndustryDetailImage.custName = response.data.custName;
                                // _this.otherIndustryDetailImage.custPhone = response.data.custPhone;
                                // _this.otherIndustryDetailImage.isWeixin = response.data.isWeixin;
                                let val = response.data.fileList
                                _this.url=val[0].url;
                                var urlList = [] ;
                                for(var i = 0; i < val.length; i++) {
                                    urlList[i] = val[i].url;
                                }
                                _this.srcList= urlList;
                            } else {
                            }
                        }
                    });
                },
                getOtherIndustryFn:function (){
                    var _this = this;
                    if (_this.$refs.villageTable.selections.length === 0) {
                        _this.$message({message: '请选择至少一个选项', type: 'warning'});
                        return;
                    }
                    _this.otherIndustryDialogVisible=true;
                    _this.otherIndustryData = {condition: JSON.stringify({
                        id: this.$refs.villageTable.selections[0].id
                    })}
                },
                getVillageCustListFn:function (){
                    var _this = this;
                    if (_this.$refs.villageTable.selections.length === 0) {
                        _this.$message({message: '请选择至少一个选项', type: 'warning'});
                        return;
                    }
                    if (this.$refs.villageDetailForm.formdata.mainOrOther === '1'){
                        _this.villageCustListDialogVisible=true;
                        //此处id是通过外部村庄列表取得的村id
                        _this.villageCustListData = {condition: JSON.stringify({
                                villageId: this.$refs.villageTable.selections[0].id
                            })}
                    }else if (this.$refs.villageDetailForm.formdata.mainOrOther === '2'){
                        if (this.$refs.villageDetailForm.formdata.otherIndustryName === ""){
                            _this.$message({message: '请选择次要行业', type: 'warning'});
                            return;
                        }
                        _this.otherIndustryCustListDialogVisible=true;
                        //此处id是通过外部村庄列表取得的次要行业id
                        _this.otherIndustryCustListData = {condition: JSON.stringify({
                                industryId:this.$refs.villageDetailForm.formdata.otherIndustryName
                            })}
                    }

                },
                //显示导入窗口
                importFn: function () {
                    this.importDialogVisible = true;
                },
                //取得已分配的网格员
                assignGridPersonnelFn: function () {
                    var _this = this;
                    if (_this.$refs.villageTable.selections.length === 0) {
                        _this.$message({message: '请选择至少一个选项', type: 'warning'});
                        return;
                    }
                    yufp.service.request({
                        url: backend.msmFrontWebService + '/api/villageInformation/getGridPersonnel',
                        method: 'get',
                        data: {
                            condition: JSON.stringify({
                                id:this.$refs.villageTable.selections[0].id
                            })
                        },
                        callback: function (code, message, response) {
                            if (code === 0) {
                                _this.assignGridPersonnelInfo.mrgId1 = response.data.mrgId1
                                _this.assignGridPersonnelInfo.mrgId2 = response.data.mrgId2
                            } else {
                            }
                        }
                    });
                    _this.assignGridPersonnelVisible = true;

                },
                //点击按钮查询到村信息显示在页面上
                updateOtherIndustry:function (){
                    var _this =this;
                    if (this.$refs.otherIndustryTable.selections.length !== 1) {
                        this.$message({message: '请选择一个选项', type: 'warning'});
                        return;
                    }
                    _this.updateOtherIndustryFormVisible  = true;
                    yufp.service.request({
                        url: backend.msmFrontWebService + '/api/villageInformation/getVillageIndustryInformation',
                        method: 'get',
                        data: {
                            condition: JSON.stringify({
                                industryId:this.$refs.otherIndustryTable.selections[0].industryId
                            })
                        },
                        callback: function (code, message, response) {
                            if (code === 0) {
                                var arrIntSet = []
                                if(null!=response.data.fundDemand&&""!=response.data.fundDemand){
                                    // 将字符串转换成数组，此时是字符串数组
                                    var arrString = response.data.fundDemand.split(',')
                                    // 将字符串数组的每一项转换成Number，生成一个新的数组
                                    for (let i in arrString) {
                                        arrIntSet.push(arrString[i])
                                    }
                                }
                                // 将新的Number数组，绑定到select空间的v-model上
                                _this.otherFundDemand  = arrIntSet;
                                _this.otherIndustry.industryType = response.data.industryType;
                                _this.otherIndustry.industryName = response.data.industryName;
                                _this.otherIndustry.industryCharacteristics = response.data.industryCharacteristics;
                            } else {
                            }
                        }
                    });
                },
                updateVillageInformationFunc: function () {
                    let _this=this;
                    let validate = false;
                    _this.$refs.villageInformationForm.validate(function (valid) {
                        validate = valid;
                    });
                    if (!validate) {
                        this.$message({message: '打*为必填项', type: 'warning'});
                        return;
                    }
                    //多选框数据处理
                    let s = []
                    for(let i = 0; i < this.fundDemand.length; i++) {
                        s.push(this.fundDemand[i])
                    }
                    this.fundDemand = s.join();
                    yufp.service.request({
                        url: backend.msmFrontWebService + '/api/villageInformation/updateVillageInformation' ,
                        method: 'get',
                        data: {
                            condition: JSON.stringify({
                                id:this.$refs.villageTable.selections[0].id,
                                mrgId: _this.villageInfo.mrgId,
                                villageName:_this.villageInfo.villageName,
                                orgId:_this.villageInfo.orgId,
                                villageSecretaryName:_this.villageInfo.villageSecretaryName,
                                phoneNo:_this.villageInfo.phoneNo,
                                familiarityLevel:_this.villageInfo.familiarityLevel,
                                womanDirectorName:_this.villageInfo.womanDirectorName,
                                womanPhoneNo:_this.villageInfo.womanPhoneNo,
                                womanFamiliarityLevel:_this.villageInfo.womanFamiliarityLevel,
                                industryType:_this.villageInfo.industryType,
                                industryName:_this.villageInfo.industryName,
                                industryCharacteristics:_this.villageInfo.industryCharacteristics,
                                fundDemand:_this.fundDemand,
                                accountingName : _this.villageInfo.accountingName,
                                accountingPhoneNo : _this.villageInfo.accountingPhoneNo,
                                accountingFamiliarityLevel : _this.villageInfo.accountingFamiliarityLevel,
                                captainName : _this.villageInfo.captainName,
                                captainPhoneNo : _this.villageInfo.captainPhoneNo,
                                captainFamiliarityLevel : _this.villageInfo.captainFamiliarityLevel
                            })
                        },
                        callback: function (code, message, response) {
                            _this.addVillageInformationFormVisible  = false;
                            _this.$nextTick(function () {
                                if (_this.$refs.villageInfo){
                                    _this.$refs.villageInfo.resetFields();
                                }
                            });
                            _this.$refs.villageTable.remoteData();
                            _this.$message({message: '更新客户成功', type: 'success'});
                        }
                    });
                },
                updateOtherIndustryFunc: function () {
                    let _this=this;
                    let validate = false;
                    _this.$refs.updateOtherIndustryForm.validate(function (valid) {
                        validate = valid;
                    });
                    if (!validate) {
                        this.$message({message: '打*为必填项', type: 'warning'});
                        return;
                    }
                    //多选框数据处理
                    let s = []
                    for(let i = 0; i < this.otherFundDemand.length; i++) {
                        s.push(this.otherFundDemand[i])
                    }
                    this.otherFundDemand = s.join();
                    yufp.service.request({
                        url: backend.msmFrontWebService + '/api/villageInformation/updateOtherIndustry' ,
                        method: 'get',
                        data: {
                            condition: JSON.stringify({
                                industryId:this.$refs.otherIndustryTable.selections[0].industryId,
                                industryType:_this.otherIndustry.industryType,
                                industryName:_this.otherIndustry.industryName,
                                industryCharacteristics:_this.otherIndustry.industryCharacteristics,
                                fundDemand:_this.otherFundDemand,
                            })
                        },
                        callback: function (code, message, response) {
                            _this.updateOtherIndustryFormVisible  = false;
                            _this.$nextTick(function () {
                                if (_this.$refs.updateOtherIndustryForm){
                                    _this.$refs.updateOtherIndustryForm.resetFields();
                                }
                            });
                            _this.$refs.otherIndustryTable.remoteData();
                            _this.$message({message: '更新次要行业成功', type: 'success'});
                        }
                    });
                },
                updateVillageDetailFunc: function () {
                    let _this=this;
                    let validate = false;
                    _this.$refs.villageDetailForm.validate(function (valid) {
                        validate = valid;
                    });
                    if (!validate) {
                        this.$message({message: '请填写对应信息', type: 'warning'});
                        return;
                    }
                    if (this.$refs.villageDetailForm.formdata.mainOrOther === '1'){
                        yufp.service.request({
                            url: backend.msmFrontWebService + '/api/villageInformation/addVillageDetail' ,
                            method: 'get',
                            data: {
                                condition: JSON.stringify({
                                    //此处传入的id为村id传入后值作为列表查询用
                                    id:this.$refs.villageTable.selections[0].id,
                                    fileList:_this.imageList,
                                    custName:_this.villageDetail.custName,
                                    isWeixin:_this.villageDetail.isWeixin,
                                    custPhone:_this.villageDetail.custPhone
                                })
                            },
                            callback: function (code, message, response) {
                                _this.updateVillageDetailVisible  = false;
                                _this.$nextTick(function () {
                                    if (_this.$refs.villageDetailForm){
                                        _this.$refs.villageDetailForm.resetFields();
                                    }
                                });
                                _this.$message({message: '更新村信息收集成功', type: 'success'});
                            }
                        });
                    }else if (this.$refs.villageDetailForm.formdata.mainOrOther === '2'){
                        if (this.$refs.villageDetailForm.formdata.otherIndustryName === ""){
                            _this.$message({message: '请选择次要行业', type: 'warning'});
                            return;
                        }
                        yufp.service.request({
                            url: backend.msmFrontWebService + '/api/villageInformation/addOtherIndustryDetail' ,
                            method: 'get',
                            data: {
                                condition: JSON.stringify({
                                    //此处传入的是次要行业id方便列表展示
                                    industryId:this.$refs.villageDetailForm.formdata.otherIndustryName,
                                    fileList:_this.imageList,
                                    custName:_this.villageDetail.custName,
                                    isWeixin:_this.villageDetail.isWeixin,
                                    custPhone:_this.villageDetail.custPhone
                                })
                            },
                            callback: function (code, message, response) {
                                _this.updateVillageDetailVisible  = false;
                                _this.$nextTick(function () {
                                    if (_this.$refs.otherIndustryDetailForm){
                                        _this.$refs.otherIndustryDetailForm.resetFields();
                                    }
                                });
                                _this.$message({message: '更新次要行业信息收集成功', type: 'success'});
                            }
                        });
                    }
                    else{
                        this.$message({message: '请选择行业类别', type: 'warning'});
                    }

                },
                //更新次要行业信息收集
                updateOtherIndustryDetailFunc: function () {
                    let _this=this;
                    let validate = false;
                    _this.$refs.otherIndustryDetailForm.validate(function (valid) {
                        validate = valid;
                    });
                    if (!validate) {
                        this.$message({message: '打*为必填项', type: 'warning'});
                        return;
                    }

                },
                //关闭移交客户弹窗
                closeAssignGridPersonnelDialog: function () {
                    var _this =this;
                    this.loading = false;
                    this.assignGridPersonnelVisible = false;
                    _this.$nextTick(function () {
                        if (_this.$refs.assignGridPersonnelForm){
                            _this.$refs.assignGridPersonnelForm.resetFields();
                        }
                    });
                },
                addVillage:function (){
                    // console.log(this.$refs.villageTable.selections)
                    var _this =this;
                    if (_this.$refs.addVillageForm){
                        _this.$refs.addVillageForm.resetFields();
                    }
                    _this.addVillageVisible = true;
                },
            }
        });
    };

    // 消息处理
    exports.onmessage = function (type, message) { };

    // page销毁时触发destroy方法
    exports.destroy = function (id, cite) {};
});
